import http from './interface'

//设置域名前缀
const baseUrl = 'http://moran.moranblog.cn/api/';
//设置appid
const appid = '10000';

http.config.baseUrl = baseUrl;
http.debugger = false;
//设置请求前拦截器
http.interceptor.request = (config) => {
	config.data.appid = appid;
	//获取本地token
	let token = uni.getStorageSync('usertoken');
	if (token) {
		config.data.usertoken = token;
	}
	//判断请求接口是都在这个数组中在的话就不显示loading
	// let noLoading = ['get_chat_log', 'get_message_list', 'get_unread_message_notifications'];
	// var url_array = config.url.split('/');
	// if (noLoading.indexOf(url_array[4]) == -1) {
	// 	uni.showLoading({
	// 		title: '加载中...',
	// 		mask: true
	// 	});
	// }
}
//设置请求结束后拦截器
http.interceptor.response = (response) => {
	uni.hideLoading();
	//判断返回状态 执行相应操作
	if (response.data.code == 1) {
		return response.data;
	} else if (response.data.code == 0 || response.data.code == 103 || response.data.code == 102) {
		uni.showToast({
			title: response.data.msg,
			duration: 2000,
			icon: 'none'
		});
		return response.data;
	} else if (response.data.code == 101) {
		//跳转页面
		uni.navigateTo({
			url: '/pages/index/maintenance?msg=' + response.data.msg
		});
	} else if (response.data.code == 401 || response.data.code == 403) {
		uni.navigateTo({
			url: '/pages/login/login'
		});
		//清楚本地token
		uni.removeStorageSync('usertoken');
		uni.removeStorageSync('username');
		uni.removeStorageSync('userid');
	}
}

export default {
	baseUrl,
	appid,
	//登录
	login(data) {
		return http.request({
			url: 'login',
			method: 'POST',
			data,
		})
	},
	//注册
	register(data) {
		return http.request({
			url: 'register',
			method: 'POST',
			data,
		})
	},
	//获取app信息
	get_app_info(data) {
		return http.request({
			url: 'get_app_info',
			method: 'POST',
			data,
		})
	},
	//获取随机文章
	get_recommended_posts(data) {
		return http.request({
			url: 'get_recommended_posts',
			method: 'POST',
			data,
		})
	},
	//获取文章列表
	get_posts_list(data) {
		return http.request({
			url: 'get_posts_list',
			method: 'POST',
			data,
		})
	},
	//获取文章信息
	get_post_information(data) {
		return http.request({
			url: 'get_post_information',
			method: 'POST',
			data,
		})
	},
	//获取文章评论
	get_list_comments(data) {
		return http.request({
			url: 'get_list_comments',
			method: 'POST',
			data,
		})
	},
	//发表评论
	post_comment(data) {
		return http.request({
			url: 'post_comment',
			method: 'POST',
			data,
		})
	},
	//点赞文章
	like_posts(data) {
		return http.request({
			url: 'like_posts',
			method: 'POST',
			data,
		})
	},
	//收藏文章
	collection_posts(data) {
		return http.request({
			url: 'collection_posts',
			method: 'POST',
			data,
		})
	},
	//赞赏文章
	reward_posts(data) {
		return http.request({
			url: 'reward_posts',
			method: 'POST',
			data,
		})
	},
	//关注用户
	follow_users(data) {
		return http.request({
			url: 'follow_users',
			method: 'POST',
			data,
		})
	},
	// 获取用户关注列表
	get_follow_list(data) {
		return http.request({
			url: 'get_follow_list',
			method: 'POST',
			data,
		})
	},
	//获取用户粉丝列表
	get_fan_list(data) {
		return http.request({
			url: 'get_fan_list',
			method: 'POST',
			data,
		})
	},
	//获取用户信息
	get_user_information(data) {
		return http.request({
			url: 'get_user_information',
			method: 'POST',
			data,
		})
	},
	user_sign_in(data) {
		return http.request({
			url: 'user_sign_in',
			method: 'POST',
			data,
		})
	},
	//获取板块列表
	get_section_list(data) {
		return http.request({
			url: 'get_section_list',
			method: 'POST',
			data,
		})
	},
	// 发布文章
	post(data) {
		return http.request({
			url: 'post',
			method: 'POST',
			data,
		})
	},
	// 编辑文章
	edit_post(data) {
		return http.request({
			url: 'edit_post',
			method: 'POST',
			data,
		})
	},
	delete_post(data) {
		return http.request({
			url: 'delete_post',
			method: 'POST',
			data,
		})
	},
	//获取板块信息
	get_section_information(data) {
		return http.request({
			url: 'get_section_information',
			method: 'POST',
			data,
		})
	},
	//获取用户消息列表
	get_message_list(data) {
		return http.request({
			url: 'get_message_list',
			method: 'POST',
			data,
		})
	},
	//获取聊天记录
	get_chat_log(data) {
		return http.request({
			url: 'get_chat_log',
			method: 'POST',
			data,
		})
	},
	//发送消息
	send_message(data) {
		return http.request({
			url: 'send_message',
			method: 'POST',
			data,
		})
	},
	// 获取系统消息
	get_message_notifications(data) {
		return http.request({
			url: 'get_message_notifications',
			method: 'POST',
			data,
		})
	},
	// 获取系统消息未读数量
	get_unread_message_notifications(data) {
		return http.request({
			url: 'get_unread_message_notifications',
			method: 'POST',
			data,
		})
	},
	// 获取登录用户信息
	get_user_other_information(data) {
		return http.request({
			url: 'get_user_other_information',
			method: 'POST',
			data,
		})
	},
	//修改用户信息
	modify_user_information(data) {
		return http.request({
			url: 'modify_user_information',
			method: 'POST',
			data,
		})
	},
	//获取收藏记录
	get_collection_records(data) {
		return http.request({
			url: 'get_collection_records',
			method: 'POST',
			data,
		})
	},
	//获取邮箱验证码
	get_email_verification_code(data) {
		return http.request({
			url: 'get_email_verification_code',
			method: 'POST',
			data,
		})
	},
	//找回密码
	retrieve_password(data) {
		return http.request({
			url: 'retrieve_password',
			method: 'POST',
			data,
		})
	},
	// 获取用户帖子浏览历史
	browse_history(data) {
		return http.request({
			url: 'browse_history',
			method: 'POST',
			data,
		})
	},
	// 获取手机号验证码
	get_mobile_verification_code(data) {
		return http.request({
			url: 'get_mobile_verification_code',
			method: 'POST',
			data,
		})
	},
	// 修改手机号
	modify_user_phone(data) {
		return http.request({
			url: 'modify_user_phone',
			method: 'POST',
			data,
		})
	},
	// 修改邮箱
	modify_user_email(data) {
		return http.request({
			url: 'modify_user_email',
			method: 'POST',
			data,
		})
	},
	// 修改密码
	change_password(data) {
		return http.request({
			url: 'change_password',
			method: 'POST',
			data,
		})
	},
	post_status_modification(data) {
		return http.request({
			url: 'post_status_modification',
			method: 'POST',
			data,
		})
	},
	// 删除评论
	delete_comment(data) {
		return http.request({
			url: 'delete_comment',
			method: 'POST',
			data,
		})
	},
	// 获取举报标签
	get_labels(data) {
		return http.request({
			url: 'get_labels',
			method: 'POST',
			data,
		})
	},
	reporting(data) {
		return http.request({
			url: 'reporting',
			method: 'POST',
			data,
		})
	},
	// 获取举报记录
	get_user_reporting(data) {
		return http.request({
			url: 'get_user_reporting',
			method: 'POST',
			data,
		})
	},
	// 退出登录
	log_out_login(data) {
		return http.request({
			url: 'log_out_login',
			method: 'POST',
			data,
		})
	}
}